<template>
  <div class="index">
    <h2>List 首页</h2>
    <li v-for="result in results" :key="result.index">
      {{ result.name }}
    </li>
    <router-link to="list/addUnit">addUnit</router-link>
  </div>
</template>

<script>
// 引入axios
import axios from 'axios'
export default {
  name: 'index',
  data () {
    return {
      results: []
    }
  },
  methods: {
    // 获取单元名称
    getUnitList () {
      axios.post('http://localhost:3000/units/getUnit', {
      }).then(this.getUnitListSucc)
    },
    // 处理获取到的数据
    getUnitListSucc (res) {
      // 把数据赋值到data实例中
      this.results = res.data.results
    }
  },
  mounted () {
    this.getUnitList()
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
